﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright company="Microsoft Corp." file="XmlHelperTests.cs">
//   All rights reserved. See License.txt in the project root for license information.
// </copyright>
// 
// --------------------------------------------------------------------------------------------------------------------
namespace AzureManagementTests
{
    using AzureManagement;
    using AzureManagement.AzureDataContracts;

    using Common;

    using Xunit;

    public class XmlHelperTests
    {
        [Fact]
        public void CanDeserialize()
        {
            const string TestResponse = @"<?xml version=""1.0"" encoding=""utf-8""?>
                                <HostedService xmlns=""http://schemas.microsoft.com/windowsazure"">
                                  <Url>hosted-service-url</Url>
                                  <ServiceName>hosted-service-name</ServiceName>
                                  <HostedServiceProperties>
                                    <Description>description</Description>
                                    <AffinityGroup>affinity-group</AffinityGroup> 
                                    <Location>location</Location >
                                    <Label>base-64-encoded-name-of-the-service</Label>
                                  </HostedServiceProperties>
                                </HostedService>";

            var data = XmlHelper.Deserialize<HostedService>(TestResponse);

            Assert.Equal("hosted-service-url", data.Url);
            Assert.Equal("hosted-service-name", data.ServiceName);
            Assert.Equal("description", data.HostedServiceProperties.Description);
            Assert.Equal("affinity-group", data.HostedServiceProperties.AffinityGroup);
            Assert.Equal("location", data.HostedServiceProperties.Location);
            Assert.Equal("base-64-encoded-name-of-the-service", data.HostedServiceProperties.Label);
        }

        [Fact]
        public void CanSerialize()
        {
            var hostedService = new HostedService
                                    {
                                        Url = "url", 
                                        ServiceName = "servicename", 
                                        HostedServiceProperties =
                                            new HostedServiceProperties
                                                {
                                                    AffinityGroup = "affinitygroup", 
                                                    Description = "description", 
                                                    Label = "label", 
                                                    Location = "location"
                                                }
                                    };

            var str = XmlHelper.Serialize(hostedService);

            const string Expected = @"<?xml version=""1.0"" encoding=""utf-8""?>
                                <HostedService xmlns=""http://schemas.microsoft.com/windowsazure"">
                                  <Url>url</Url>
                                  <ServiceName>servicename</ServiceName>
                                  <HostedServiceProperties>
                                    <Description>description</Description>
                                    <AffinityGroup>affinitygroup</AffinityGroup> 
                                    <Location>location</Location >
                                    <Label>label</Label>
                                  </HostedServiceProperties>
                                </HostedService>";

            Assert.True(str.Contains("<ServiceName>servicename</ServiceName>"));
        }
    }
}